package com.google.coffeeshop.gui.desktop;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Component;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import com.google.coffeeshop.gui.desktop.employee.EmployeeActionsPanel;
import com.google.coffeeshop.gui.desktop.employee.EmployeePanel;
import com.google.coffeeshop.gui.desktop.orderpayment.OrderPaymentActionsPanel;
import com.google.coffeeshop.gui.desktop.orderpayment.OrderPaymentPanel;
import com.google.coffeeshop.gui.desktop.product.ProductActionPanel;
import com.google.coffeeshop.gui.desktop.product.ProductPanel;
import com.google.coffeeshop.gui.desktop.receiptnote.ReceiptNoteActionsPanel;
import com.google.coffeeshop.gui.desktop.receiptnote.ReceiptNotePanel;
import com.google.coffeeshop.gui.desktop.seat.SeatActionPanel;
import com.google.coffeeshop.gui.desktop.seat.SeatPanel;
import com.google.coffeeshop.gui.desktop.statistics.StatisticsActionsPanel;
import com.google.coffeeshop.gui.desktop.statistics.StatisticsPanel;

public class MainPanel extends AbstractBasePanel {

	private static final long serialVersionUID = 1L;
	private JPanel actionsPanel;
	private CardLayout cardLayout = new CardLayout(5, 0);

	private AppFrame parent;
	
	public MainPanel(final AppFrame parent) {
		this.parent = parent;
		setLayout(new BorderLayout(0, 0));
		
		JPanel contentPanel = new JPanel();
		add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(new CardLayout(0, 0));
		
		actionsPanel = new JPanel();
		actionsPanel.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		add(actionsPanel, BorderLayout.NORTH);
		actionsPanel.setLayout(cardLayout);
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent e) {
				JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
				int index = tabbedPane.getSelectedIndex();
				Component component = tabbedPane.getComponent(index);
				if (null != component && component instanceof ContentBasePanel) {
					ContentBasePanel contentBasePanel = (ContentBasePanel)component;
					cardLayout.show(actionsPanel, contentBasePanel.getConstraints());
				}
			}
		});
		tabbedPane.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		contentPanel.add(tabbedPane, "name_7237348206262");
		
		OrderPaymentActionsPanel pnlOrderPaymentActions = new OrderPaymentActionsPanel();
		OrderPaymentPanel pnlOrderPayment = new OrderPaymentPanel("orderPayment", pnlOrderPaymentActions, this);
		pnlOrderPaymentActions.setOrderPaymentPanel(pnlOrderPayment);
		tabbedPane.addTab("Order & Payment", new ImageIcon(MainPanel.class.getResource("/com/google/coffeeshop/gui/desktop/icon/size16/payment-16.png")), pnlOrderPayment, null);
		actionsPanel.add(pnlOrderPaymentActions, pnlOrderPayment.getConstraints());
		
		
		StatisticsPanel pnlStatistics = new StatisticsPanel("statistics");
		tabbedPane.addTab("Statistics & Report", new ImageIcon(MainPanel.class.getResource("/com/google/coffeeshop/gui/desktop/icon/size16/statistics-16.png")), pnlStatistics, null);
		
		ReceiptNotePanel pnlReceiptNote = new ReceiptNotePanel("receiptNote");
		tabbedPane.addTab("Receipt Note", new ImageIcon(MainPanel.class.getResource("/com/google/coffeeshop/gui/desktop/icon/size16/receipt-16.png")), pnlReceiptNote, null);
		
		EmployeePanel pnlEmployee = new EmployeePanel("employee");
		tabbedPane.addTab("Employee", new ImageIcon(MainPanel.class.getResource("/com/google/coffeeshop/gui/desktop/icon/size16/waiter-16.png")), pnlEmployee, null);
		
		ProductPanel pnlProduct = new ProductPanel("product");
		tabbedPane.addTab("Product", new ImageIcon(MainPanel.class.getResource("/com/google/coffeeshop/gui/desktop/icon/size16/product-16.png")), pnlProduct, null);
		
		SeatPanel pnlSeat = new SeatPanel("seat");
		tabbedPane.addTab("Seat", new ImageIcon(MainPanel.class.getResource("/com/google/coffeeshop/gui/desktop/icon/size16/chair-16.png")), pnlSeat, null);
		
		
		ReceiptNoteActionsPanel pnlReceiptNoteActions = new ReceiptNoteActionsPanel(pnlReceiptNote);
		actionsPanel.add(pnlReceiptNoteActions, pnlReceiptNote.getConstraints());
		
		StatisticsActionsPanel pnlStatisticsActions = new StatisticsActionsPanel(pnlStatistics);
		actionsPanel.add(pnlStatisticsActions, pnlStatistics.getConstraints());
		
		EmployeeActionsPanel pnlEmployeeActions = new EmployeeActionsPanel(pnlEmployee);
		actionsPanel.add(pnlEmployeeActions, pnlEmployee.getConstraints());
		
		ProductActionPanel pnlProductActions = new ProductActionPanel(pnlProduct);
		actionsPanel.add(pnlProductActions, pnlProduct.getConstraints());
		
		SeatActionPanel pnlSeatActions = new SeatActionPanel(pnlSeat, pnlOrderPayment);
		actionsPanel.add(pnlSeatActions, pnlSeat.getConstraints());
	}
	
	public void refreshGUI() {
		parent.refreshGUI();
	}
	
}
